/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package common.statistics;

import common.io.Format;

/**
 *
 * @author risto
 */
public class NormalDistImpl implements NormalDist {
    private double mean, stdev;

    @Override
    public String toString() {
        return "(" + Format.formatFloat(mean) + " +- " + Format.formatFloat(stdev) + ")";
    }

    public NormalDistImpl() {
    }

    public NormalDistImpl(double mean, double stdev) {
        this.mean = mean;
        this.stdev = stdev;
    }

    public NormalDistImpl(double[] data) {
        double sum = 0, dsum = 0;
        for (double d : data) sum += d;
        this.mean = sum / data.length;
        for (double d : data) dsum += Math.pow(d - mean, 2);
        this.stdev = Math.sqrt(dsum / (data.length - 1));
    }

    /**
     * @param other - another normal distribution
     * @return distance between two distributions
     */
    public double distance(NormalDist other)
    {
        double d1 = other.getMean() - this.mean;
        double d2 = other.getStdev() - this.stdev;
        return Math.sqrt(d1*d1+d2*d2);
    }

    public double getMean() {
        return mean;
    }

    public void setMean(double mean) {
        this.mean = mean;
    }

    public double getStdev() {
        return stdev;
    }

    public void setStdev(double stdev) {
        this.stdev = stdev;
    }

    
}
